[XEN] Clean up some x86 bootstrap code. Replace some CPU iterators
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 22 Aug 2006 10:19:48 +0000 (11:19 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 22 Aug 2006 10:19:48 +0000 (11:19 +0100)
with for_each_cpu() -- we want to ensure that per_cpu areas are
accessed only for cpus in cpu_possible_map.
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/arch/x86/domain.c
xen/arch/x86/setup.c
xen/arch/x86/smpboot.c
xen/arch/x86/x86_32/mm.c
xen/arch/x86/x86_64/mm.c
xen/common/sched_sedf.c
xen/common/schedule.c
xen/common/timer.c
xen/include/asm-x86/page.h

index 38590f08f6c1c4dcd7e4a2fc6ede1553604e7a6d..f2bb9a5920a12ec9466fdae4c75cb7bdd0da66cf 100644 (file)
@@ -125,8 +125,15 @@ struct vcpu *alloc_vcpu_struct(struct domain *d, unsigned int vcpu_id)
 
     v->arch.flags = TF_kernel_mode;
 
-    v->arch.schedule_tail = is_idle_domain(d) ?
-        continue_idle_domain : continue_nonidle_domain;
+    if ( is_idle_domain(d) )
+    {
+        v->arch.schedule_tail = continue_idle_domain;
+        v->arch.cr3           = __pa(idle_pg_table);
+    }
+    else
+    {
+        v->arch.schedule_tail = continue_nonidle_domain;
+    }
 
     v->arch.ctxt_switch_from = paravirt_ctxt_switch_from;
     v->arch.ctxt_switch_to   = paravirt_ctxt_switch_to;
index 01782320b3348e6fb2eb91296241e095727cb455..2d77a506dc37e400075fadf91af026779ebd9b47 100644 (file)
@@ -190,10 +190,26 @@ static void percpu_free_unused_areas(void)
                        __pa(__per_cpu_end));
 }
 
+static void init_idle_domain(void)
+{
+    struct domain *idle_domain;
+
+    /* Domain creation requires that scheduler structures are initialised. */
+    scheduler_init();
+
+    idle_domain = domain_create(IDLE_DOMAIN_ID);
+    if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
+        BUG();
+
+    set_current(idle_domain->vcpu[0]);
+    idle_vcpu[0] = this_cpu(curr_vcpu) = current;
+
+    setup_idle_pagetable();
+}
+
 void __init __start_xen(multiboot_info_t *mbi)
 {
     char __cmdline[] = "", *cmdline = __cmdline;
-    struct domain *idle_domain;
     unsigned long _initrd_start = 0, _initrd_len = 0;
     unsigned int initrdidx = 1;
     module_t *mod = (module_t *)__va(mbi->mods_addr);
@@ -212,6 +228,7 @@ void __init __start_xen(multiboot_info_t *mbi)
     cmdline_parse(cmdline);
 
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
+    idle_vcpu[0] = current;
     set_processor_id(0); /* needed early, for smp_processor_id() */
 
     smp_prepare_boot_cpu();
@@ -437,16 +454,6 @@ void __init __start_xen(multiboot_info_t *mbi)
 
     early_cpu_init();
 
-    scheduler_init();
-
-    idle_domain = domain_create(IDLE_DOMAIN_ID);
-    if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
-        BUG();
-
-    set_current(idle_domain->vcpu[0]);
-    this_cpu(curr_vcpu) = idle_domain->vcpu[0];
-    idle_vcpu[0] = current;
-
     paging_init();
 
     /* Unmap the first page of CPU0's stack. */
@@ -477,6 +484,8 @@ void __init __start_xen(multiboot_info_t *mbi)
 
     init_IRQ();
 
+    init_idle_domain();
+
     trap_init();
 
     timer_init();
index 734bd41797a56284c01dff6bdbf8588bc59d2ace..39cbbd92823fcd8a2c2dba521d920e7773d799bb 100644 (file)
@@ -896,8 +896,6 @@ static int __devinit do_boot_cpu(int apicid, int cpu)
        v = alloc_idle_vcpu(cpu);
        BUG_ON(v == NULL);
 
-       v->arch.cr3 = __pa(idle_pg_table);
-
        /* start_eip had better be page-aligned! */
        start_eip = setup_trampoline();
 
index dc2450201a7c381c37248a77f231f56dce47fa0e..116228a53db90b2e250bb03958763ec1173e71c4 100644 (file)
@@ -75,8 +75,6 @@ void __init paging_init(void)
     printk("PAE disabled.\n");
 #endif
 
-    idle_vcpu[0]->arch.cr3 = __pa(idle_pg_table);
-
     if ( cpu_has_pge )
     {
         /* Suitable Xen mapping can be GLOBAL. */
@@ -120,8 +118,12 @@ void __init paging_init(void)
         idle_pg_table_l2[l2_linear_offset(IOREMAP_VIRT_START) + i] =
             l2e_from_page(virt_to_page(ioremap_pt), __PAGE_HYPERVISOR);
     }
+}
+
+void __init setup_idle_pagetable(void)
+{
+    int i;
 
-    /* Install per-domain mappings for idle domain. */
     for ( i = 0; i < PDPT_L2_ENTRIES; i++ )
         idle_pg_table_l2[l2_linear_offset(PERDOMAIN_VIRT_START) + i] =
             l2e_from_page(virt_to_page(idle_vcpu[0]->domain->
index f173c05d831048c38ea20e5af41445abe2525bad..279d54220cea22e7a83853062d8ce60d6232bae8 100644 (file)
@@ -81,8 +81,6 @@ void __init paging_init(void)
     l2_pgentry_t *l2_ro_mpt;
     struct page_info *pg;
 
-    idle_vcpu[0]->arch.cr3 = __pa(idle_pg_table);
-
     /* Create user-accessible L2 directory to map the MPT for guests. */
     l3_ro_mpt = alloc_xenheap_page();
     clear_page(l3_ro_mpt);
@@ -121,7 +119,10 @@ void __init paging_init(void)
     /* Set up linear page table mapping. */
     idle_pg_table[l4_table_offset(LINEAR_PT_VIRT_START)] =
         l4e_from_paddr(__pa(idle_pg_table), __PAGE_HYPERVISOR);
+}
 
+void __init setup_idle_pagetable(void)
+{
     /* Install per-domain mappings for idle domain. */
     idle_pg_table[l4_table_offset(PERDOMAIN_VIRT_START)] =
         l4e_from_page(
index 4f7d6380e90dca0ab618687f2784e46e8c264ecb..f8913703acda317054d758475397e77076f523cd 100644 (file)
@@ -1301,16 +1301,9 @@ static int sedf_adjust_weights(struct sched_adjdom_cmd *cmd)
 {
     struct vcpu *p;
     struct domain      *d;
-    int                 sumw[NR_CPUS];
-    s_time_t            sumt[NR_CPUS];
-    int                 cpu;
+    int                 sumw[NR_CPUS] = { 0 };
+    s_time_t            sumt[NR_CPUS] = { 0 };
  
-    for ( cpu = 0; cpu < NR_CPUS; cpu++ )
-    {
-        sumw[cpu] = 0;
-        sumt[cpu] = 0;
-    }
-
     /* Sum across all weights. */
     for_each_domain( d )
     {
index 801966f38a6912e4af1b8de1dc2077630f231cd9..c65346d7fb134d4fc33ee63c206e3cb56d151bfa 100644 (file)
@@ -633,7 +633,7 @@ void __init scheduler_init(void)
 
     open_softirq(SCHEDULE_SOFTIRQ, __enter_scheduler);
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for_each_cpu ( i )
     {
         spin_lock_init(&per_cpu(schedule_data, i).schedule_lock);
         init_timer(&per_cpu(schedule_data, i).s_timer, s_timer_fn, NULL, i);
index 8f2fa9964edd2fd5923230eb84e9186d30ce30d6..618906db384c4f219b3547f6fce46a1433ce691f 100644 (file)
@@ -382,7 +382,7 @@ void __init timer_init(void)
     SET_HEAP_SIZE(&dummy_heap, 0);
     SET_HEAP_LIMIT(&dummy_heap, 0);
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for_each_cpu ( i )
     {
         spin_lock_init(&per_cpu(timers, i).lock);
         per_cpu(timers, i).heap = &dummy_heap;
index 94158c7f3d199270ecd20b0ac9ce322e8700a219..01ab4be3c79e5df3e371e1ea184f6e04433779e7 100644 (file)
@@ -255,7 +255,8 @@ extern l2_pgentry_t   idle_pg_table_l2[ROOT_PAGETABLE_ENTRIES*L2_PAGETABLE_ENTRI
 extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];
 extern l2_pgentry_t   idle_pg_table_l2[ROOT_PAGETABLE_ENTRIES];
 #endif
-extern void paging_init(void);
+void paging_init(void);
+void setup_idle_pagetable(void);
 #endif
 
 #define __pge_off()                                                     \